package ${serviceimplPackage};

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ${entityPackage}.${entityClassName};
import ${mapperPackage}.${entityClassName}Mapper;
import ${servicePackage}.${entityClassName}Service;
import ${voPackage}.${entityClassName}Vo;
import ${wrapperPackage}.${entityClassName}Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
<#if packageExtend??>
<#list packageExtend as item>
import ${item};
</#list>
</#if>
import org.springframework.util.CollectionUtils;
import java.util.stream.Collectors;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ${entityClassName}ServiceImpl extends ServiceImpl<${entityClassName}Mapper, ${entityClassName}> implements ${entityClassName}Service {

    @Autowired
    ${entityClassName}Mapper ${entityClassName?uncap_first}Mapper;

<#if propertyExtend??>
<#list propertyExtend as item>
    ${item}
</#list>
</#if>

    private ${entityClassName}Wrapper ${entityClassName?uncap_first}Wrapper = new ${entityClassName}Wrapper();

    @Override
    public ${entityClassName}Vo addOne(${entityClassName}Vo ${entityClassName?uncap_first}Vo) {
        ${entityClassName} entity = ${entityClassName?uncap_first}Vo.convertTo${entityClassName}();
        save(entity);
        return ${entityClassName}Vo.convertTo${entityClassName}Vo(entity);
    }

    @Override
    public ${entityClassName}Vo getOneByCode(String code) {
        return ${entityClassName}Vo.convertTo${entityClassName}Vo(getById(code));
    }

    @Override
    public Integer update(${entityClassName}Vo ${entityClassName?uncap_first}Vo) {
        return this.${entityClassName?uncap_first}Mapper.updateById(${entityClassName?uncap_first}Vo.convertTo${entityClassName}());
    }

    @Override
    public Integer delete(String code) {
        return this.${entityClassName?uncap_first}Mapper.deleteById(code);
    }

    @Override
    public Integer batchDelete(List<String> codes) {
        return this.${entityClassName?uncap_first}Mapper.deleteBatchIds(codes);
    }

    @Override
    public List<${entityClassName}Vo> findPage(Page page, ${entityClassName}Vo ${entityClassName?uncap_first}Vo) {
        this.${entityClassName?uncap_first}Mapper.selectPage(page, ${entityClassName?uncap_first}Wrapper.getWrapper(${entityClassName?uncap_first}Vo));
        List<${entityClassName}Vo> list = (List<${entityClassName}Vo>)${entityClassName}Vo.list${entityClassName}Vo(page.getRecords());
        page.setRecords(null);
        return list;
    }

    @Override
    public Integer count(${entityClassName}Vo ${entityClassName?uncap_first}Vo) {
        return this.${entityClassName?uncap_first}Mapper.selectCount(${entityClassName?uncap_first}Wrapper.getWrapper(${entityClassName?uncap_first}Vo));
    }

    @Override
    public List<${entityClassName}Vo> findAll(${entityClassName}Vo ${entityClassName?uncap_first}Vo) {
        return ${entityClassName}Vo.list${entityClassName}Vo(list(${entityClassName?uncap_first}Wrapper.getWrapper(${entityClassName?uncap_first}Vo)));
    }

    @Override
    public Integer saveBatch(List<${entityClassName}Vo> ${entityClassName?uncap_first}Vos) {
        saveBatch(${entityClassName}Vo.list${entityClassName}(${entityClassName?uncap_first}Vos));
        return ${entityClassName?uncap_first}Vos.size();
    }

    @Override
    public boolean updateOrSaveBatch(List<${entityClassName}Vo> ${entityClassName?uncap_first}Vos) {
        return saveOrUpdateBatch(${entityClassName}Vo.list${entityClassName}(${entityClassName?uncap_first}Vos));
    }

    @Override
    public boolean updateBatch(List<${entityClassName}Vo> ${entityClassName?uncap_first}Vos) {
        return updateBatchById(${entityClassName}Vo.list${entityClassName}(${entityClassName?uncap_first}Vos));
    }

<#if methodExtend??>
<#list methodExtend as item>
    ${item}
</#list>
</#if>


}
